﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AliveCMS.Models;
using Lucene.Net.Index;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using System.Web.Script.Serialization;
namespace AliveCMS.App_Code
{
    public static class Logger
    {
        public static void LogChange<T>(ChangeViewModel<T> item)
        {
            Document doc = new Document();
            using (var indexWriter = new IndexWriter(MvcApplication.SiteData,new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30),IndexWriter.MaxFieldLength.LIMITED))
            {
                doc.Add(new Field("ObjectName", "LogChange", Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("Current", new JavaScriptSerializer().Serialize(item.Current), Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("Updated", new JavaScriptSerializer().Serialize(item.Updated), Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("Date", DateTime.Now.ToString("MM/dd/yyyy"),Field.Store.YES,Field.Index.NOT_ANALYZED));
                indexWriter.AddDocument(doc);
                indexWriter.Optimize();
            }
        }
    }
}